package com.skwyb.form.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

/**
 * 统一处理handler
 *
 * @author Administrator
 */
@Log4j2
@Service
@RequiredArgsConstructor
public class Handler<T> {

//    private final Map<String, BaseService<T>> services;
//
//
//    public BaseService<T> getService(String component) {
//        BaseService<T> service = services.get(component);
//        if (service == null) {
//            throw new BusinessException(ResultCode.FAIL);
//        }
//
//        return service;
//    }
//
//    public ObjectResult handler(String name, Integer page, Integer rows, T t) {
//        BaseService<T> service = getService(name);
//        return new ObjectResult(service.selectPageListByWhere(page, rows, t));
//    }
//
//    public ObjectResult handler(String name, T t, OperateType type) {
//        BaseService<T> service = getService(name);
//        Object object = null;
//
//        switch (type) {
//            case GET:
//                object = service.selectByPrimaryKey(t);
//                break;
//            case SELECT:
//                object = service.selectListByWhere(t);
//                break;
//            case COUNT:
//                object = service.selectCount(t);
//                break;
//            case SELECT_ALL:
//                object = service.selectAll();
//                break;
//            case SELECT_PAGE:
//                log.info("SELECT_PAGE not implements");
//                break;
//            case INSERT:
//                object = service.saveSelective(t);
//                break;
//            case SAVE:
//                object = service.save(t);
//                break;
//            case UPDATE:
//                object = service.updateSelective(t);
//                break;
//            case DELETE:
//                object = service.deleteById(t);
//                break;
//            case DELETE_WHERE:
//                object = service.deleteByWhere(t);
//                break;
//            case DELETE_BATCH:
//                log.info("DELETE_BATCH not implements");
//                break;
//            case SELECT_ONE:
//                object = service.selectOne(t);
//                break;
//            case INSET_BATCH:
//                log.info("INSET_BATCH not implements");
//                break;
//            default:
//                log.info("OperateType error.");
//                break;
//        }
//        ObjectResult result = new ObjectResult(ResultCode.SUCCESS);
//        result.setValue(object);
//        return result;
//    }
}
